<?php
header("Content-Type: text/html;charset=utf-8");

if(empty($_POST)) {exit;}

include('Includes/DB.inc.php');
include('Includes/AC.inc.php');

$id = '1';

switch($_POST['status']) {

case 'postUserMenuSort'://设置用户菜单排序
	$sort = ac::buildUserMenuSort($_POST['sort']);
	postUserMenuSort($id, $sort);
	//print_r($sort);
	exit;
break;
case 'getUserMenuSort'://获取用户菜单排序
	getUserMenuSort($id);
	exit;
break;

case 'postPurview'://设置权限
	$purview = isset($_POST['purview']) ? $_POST['purview'] : array();
	postPurview($id, 'r', $purview);
	exit;
break;
case 'getPurview'://获取权限
	getPurview($id);
	exit;
break;

default:
	print_r($_POST);
	exit;
}





#菜单排序写入数据库
function postUserMenuSort($uid, $sort=array()) {
	$userMenuSort = serialize($sort);

	$dbh = db::connect();
	$sth = $dbh->prepare("UPDATE p_ac_users SET menusort=:menusort WHERE uid=:uid LIMIT 1");
	$dbh = null;
	$sth->bindParam(':uid', $uid);
	$sth->bindParam(':menusort', $userMenuSort);
	$sth->execute();

	echo '更新 '.$sth->rowCount().' 条数据记录';
}

#数据库中获取菜单排序
function getUserMenuSort($uid) {

	$dbh = db::connect();
	$DBTP = 'p_';

	$result = ac::getUserMenuSort($uid, $dbh, $DBTP);

	print_r($result);
}






#权限写入数据库
function postPurview($id, $type, $purview=array()) {

	$dbh = db::connect();
	$dbtp = 'p_';
	echo '更新 '.ac::putPurview($id, $type, $purview, $dbh, $dbtp).' 条数据记录';



}
#数据库中获取权限
function getPurview($uid) {

	$dbh = db::connect();
	$sql = "SELECT purview FROM p_ac_users WHERE uid=:uid LIMIT 1";
	$sth = $dbh->prepare($sql);
	$dbh = null;
	$sth->bindParam(':uid',$uid);
	$sth->execute();

	$result = $sth->fetch(PDO::FETCH_ASSOC);
	$result = unserialize($result['purview']);
	print_r($result);
}